package cn.jd.controller;

import cn.jd.domain.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private RestTemplate restTemplate;
    @GetMapping("/{id}")
    @HystrixCommand(fallbackMethod = "userByIdFallbackMethod")
    public User userById(@PathVariable("id") Integer id){

        User user = restTemplate.getForObject("http://user-server/user/"+id, User.class);
        System.out.println(user);
        return user;
    }
    public User userByIdFallbackMethod(@PathVariable("id") Integer id) {
        return new User(id,"阮经天","网络繁忙请稍后再试","7411020");
    }
}
